<?php
/**
* 获取停车费用
 * 参数：时间区间   门店编号
 */

namespace app\modules\admin\models;
use app\modules\admin\models\CallProcedure;
use Yii;
use yii\base\Exception;

class GetParkingPrice
{
    public function index($starttime,$endtime,$store_id){
        $data['_ParkingUnit'] = Yii::$app->params['ParkingUnit'];//停车价单位(以多少小时为1个单位)
        $data['_ParkingUnitPrice'] = Yii::$app->params['ParkingUnitPrice'];//停车单价(1个单位多少钱)
        $data['_starttime'] = $starttime;
        $data['_endtime'] = $endtime;
        $data['_store_id'] = $store_id;
        $Procedure = new CallProcedure();
        $array['Procedure_data_in'] = $data;
        $array['Procedure_name'] = 'CalculateParkingPrice';
        $result = $Procedure->CallProcedure_query($array);
        //var_dump($result);exit;
        if (array_key_exists('result', $result)) {
            return array('successed'=>false,'msg'=>$result['value']);
        }else {
            $parkingarray['total_time'] = $result[0][0]['@total_time'];
            $parkingarray['total_price'] = $result[0][0]['@total_price'];
            $parkingarray['parking_unit'] = $result[0][0]['@_parking_unit'];
            $parkingarray['parking_unit_price'] = $result[0][0]['@_parking_unit_price'];
            return array('successed' => true, 'msg' => $parkingarray);
        }
    }


    //判断车时是否在门店营业范围内
    public function cartimestore($starttime,$endtime,$store_id){
        //判断车时时间是否在门店营业时间内
        $data_check['_str_cartime_start'] = substr($starttime,11);
        $data_check['_str_cartime_end'] = substr($endtime,11);
        $data_check['_store_id'] = $store_id;
        $Procedure = new CallProcedure();
        $checkstore['Procedure_data_in'] = $data_check;
        $checkstore['Procedure_name'] = 'UserCarTimeStoreCheck';
        $checkstoreresult = $Procedure->CallProcedure_query($checkstore);
        if($checkstoreresult[0][0]['result']=='0') {
            return false;
        }else{
            return true;
        }
    }



    //计算租金
    /*
     *
     * $buying_price  车辆购置价
     * $timedifference 行驶证年限  三档  0-3  3-6  6--
     * $is_limit_card  是否限牌
     *
     */
    public function rentcost($starttime,$endtime,$buying_price,$timedifference,$store_id){


        //门店调价     车辆购置价  行驶证注册年限
        if($timedifference==1){
            $yearcoefficient=Yii::$app->params['YearCoefficientLessThree'];//年限系数 年限≤ 3 1
        }else if($timedifference==2){
            $yearcoefficient=Yii::$app->params['YearCoefficientGreaterThreeLessSix'];//年限系数 3＜年限≤6年 0.8
        }else{
            $yearcoefficient=Yii::$app->params['YearCoefficientGreaterSix'];//年限系数 6年以上 0.6
        }

        $ProcedureData = array(
            'Procedure_name' => 'Api_CalculateRent',
            'Procedure_data_in' => array(
                '_yearcoefficient' =>$yearcoefficient,  //年限系数
                '_buying_price'=>$buying_price,  //购置价
                '_coefficient'=>Yii::$app->params['Coefficient'],//基本系数
                '_cityaddprice'=>Yii::$app->params['CityAddPrice'],//限牌价
                '_store_id'=>$store_id,
                '_workmultiple'=>Yii::$app->params['WorkMultiple'],//工作日租金倍数
                '_weekmultiple'=>Yii::$app->params['WeekMultiple'],//周末租金倍数
                '_festivalsmultiple'=>Yii::$app->params['FestivalsMultiple'],//节假日租金倍数
            ),
        );
        $Procedure = new CallProcedure();
        $result = $Procedure->CallProcedure_query($ProcedureData);

        /*
         SET @rentprice = round(@buying_price*@coefficient*@yearcoefficient*@work_multiple,2); -- 工作日租金  车辆购置价*基础系数*年限系数*工作日租金倍数
         SET @weekprice = round(@rentprice*@week_multiple,2); -- 周末租金   工作日租金*周末租金倍数
         SET @festivalsprice = round(@rentprice*@festivals_multiple,2); -- 节假日租金  工作日租金*节假日租金倍数

        SELECT @rentprice, 日租金
            @weekprice, 周末租金
            @festivalsprice 节假日租金
            @limitprice, 限牌价-----------
            @buying_price, 车辆指导价
            @coefficient, 基础系数-----------
            @work_multiple, 工作日倍数-----------
            @week_multiple, 周末租金倍数 -----------
            @festivals_multiple, 节假日租金倍数--------
            @yearcoefficient, 年限系数-------------
            @car_cash,  车辆押金
            @store_start, 门店开始营业时间
            @store_end; 门店结束营业时间

*/

        if (array_key_exists('result', $result)) {
            return array('successed'=>false,'msg'=>$result['value']);
        }else {
            $array = array();
            $work = 0;
            $weeks = 0;
            $festival = 0;
            //当前店铺的营业开始时间和营业结束时间 为了计算满足不满足6小时
            $store_start2 = date('Y-m-d', strtotime($starttime)) . ' ' . $result[0][0]['@store_end'];
            $store_end1 = date('Y-m-d', strtotime($endtime)) . ' ' . $result[0][0]['@store_start'];
            $date_price_array = array();
            //首先判断租期满不满24小时
            if ((strtotime($endtime) - strtotime($starttime)) / 3600 < 24) {
                $original_start = date("w", strtotime($starttime)); //车时开始时间是周几
                $original_end = date("w", strtotime($endtime)); //车时结束时间是周几

                $start_t = date("Y-m-d",strtotime($starttime)); //获取开始时间年月日
                $end_t = date("Y-m-d",strtotime($endtime)); //获取结束时间年月日
                $get_festival = $this->getFestivals($start_t);//判断开始时间是否是节假日
                $get_whitelist = $this->getWhiteList($start_t);//判断开始时间是否在白名单内 如果在就按照工作日算

                $get_festival_e = $this->getFestivals($end_t);//判断开始时间是否是节假日
                $get_whitelist_e = $this->getWhiteList($end_t);//判断开始时间是否在白名单内 如果在就按照工作日算
                //判断是否在同一天
                //如果在同一天
                if($start_t == $end_t){
                    //判断开始时间是否在工作日
                    if($original_start == 1 || $original_start == 2 || $original_start == 3 || $original_start == 4 || $original_start == 5){
                        //是否是节假日
                        if ($get_festival) {
                            //是否在白名单
                            if ($get_whitelist) {
                                //判断是否超过六小时
                                if((strtotime($endtime) - strtotime($starttime)) / 3600>6){
                                    $work = 1;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>1);
                                }else{
                                    $work = 0.5;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                }

                            } else {
                                if((strtotime($endtime) - strtotime($starttime)) / 3600>6){
                                    $festival = 1;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>1);
                                }else{
                                    $festival = 0.5;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                }
                            }
                        } else {
                            if((strtotime($endtime) - strtotime($starttime)) / 3600>6){
                                $work = 1;
                                $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>1);
                            }else{
                                $work = 0.5;
                                $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                            }
                        }
                    }
                    //判断开始时间是否在周六 周日
                    if ($original_start == 0 || $original_start == 6) {
                        if ($get_festival) {
                            //是节假日
                            if ($get_whitelist) {
                                //白名单  判断是否超过六小时
                                if((strtotime($endtime) - strtotime($starttime)) / 3600>6){
                                    $work = 1;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>1);
                                }else{
                                    $work = 0.5;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                }
                            } else {
                                //节假日 判断是否超过六小时
                                if((strtotime($endtime) - strtotime($starttime)) / 3600>6){
                                    $festival = 1;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>1);
                                }else{
                                    $festival = 0.5;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                }
                            }
                        } else {
                            //不是假节日
                            if ($get_whitelist) {
                                //白名单
                                if((strtotime($endtime) - strtotime($starttime)) / 3600>6){
                                    $work = 1;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>1);
                                }else{
                                    $work = 0.5;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                }

                            } else {
                                //不是白名单 是周末
                                if((strtotime($endtime) - strtotime($starttime)) / 3600>6){
                                    $weeks = 1;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>1);
                                }else{
                                    $weeks = 0.5;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                }
                            }
                        }
                    }
                }

                //如果不在同一天
                else{
                    if($original_start == 1 || $original_start == 2 || $original_start == 3 || $original_start == 4 || $original_start == 5){ //工作日
                        if($get_festival){  //是否在节假日
                            if($get_whitelist){  //开始时间是否是白名单
                                if($original_end== 1 || $original_end == 2 || $original_end == 3 || $original_end == 4 || $original_end == 5){    //如果是 判断结束时间是周几
                                    if($get_festival_e){  //判断结束时间是不是假节日
                                        if($get_whitelist_e){ //判断结束时间是否是白名单
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{  //如果不是白名单 说明结束时间 是节假日
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{
                                        $work = 1;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }
                                }
                                else{ //结束时间是周六周日 开始时间是白名单
                                    //判断结束时间是不是假节日
                                    if($get_festival_e){
                                        //判断是否是白名单
                                        if($get_whitelist_e){
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{
                                            //如果不是白名单 说明结束时间 是假节日
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日
                                        //是否是白名单
                                        if($get_whitelist_e) {
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{
                                            $work = 0.5;
                                            $weeks = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                        }

                                    }
                                }
                            }
                            else{ //开始时间不是白名单 是节假日
                                if($original_end== 1 || $original_end == 2 || $original_end == 3 || $original_end == 4 || $original_end == 5){    //如果是 判断结束时间是周几
                                    if($get_festival_e){  //判断结束时间是不是假节日
                                        if($get_whitelist_e){ //判断结束时间是否是白名单
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{  //如果结束时间不是白名单 说明结束时间 是节假日
                                            $festival = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{//开始时间是节假日 结束时间是工作日
                                        $work = 0.5;
                                        $festival = 0.5;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }
                                }
                                else{//结束时间是周六周日 开始时间是假节日
                                    //判断结束时间是不是假节日
                                    if($get_festival_e){
                                        //判断是否是白名单
                                        if($get_whitelist_e){
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{
                                            //如果不是白名单 说明结束时间 是节假日
                                            $festival = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日 是周末 开始时间是假节日
                                        //是否是白名单
                                        if($get_whitelist_e) {
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{//结束时间是周末 开始时间是假节日
                                            $festival = 0.5;
                                            $weeks = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                        }

                                    }
                                }
                            }
                        }
                        else //开始时间不是假节日 是工作日
                        {
                            if($original_end== 1 || $original_end == 2 || $original_end == 3 || $original_end == 4 || $original_end == 5){    //如果是 判断结束时间是周几
                                if($get_festival_e){  //判断结束时间是不是假节日
                                    if($get_whitelist_e){ //判断结束时间是否是白名单
                                        $work = 1;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }else{  //如果判断结束不是白名单 说明结束时间 是节假日
                                        $work = 0.5;
                                        $festival = 0.5;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                    }
                                }else{//结束时间是工作日 开始时间是工作日
                                    $work = 1;
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                }
                            }
                            else{//如果结束时间是周六周日 开始时间是工作日
                                if($get_festival_e){//判断结束时间是不是假节日
                                    //判断是否是白名单
                                    if($get_whitelist_e){
                                        $work = 1;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }else{
                                        //如果不是白名单 说明结束时间 是节假日 开始时间是工作日
                                        $work = 0.5;
                                        $festival = 0.5;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                    }
                                }else{ //结束时间不是节假日 是周六周日 开始时间是工作日
                                    if($get_whitelist_e) { //是否是白名单
                                        $work = 1;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }else{//结束时间是周六周日 开始时间是工作日
                                        $work = 0.5;
                                        $weeks = 0.5;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                    }
                                }
                            }
                        }
                    }
                    //周末 大前提是开始时间是周末
                    else
                    {
                        if($get_festival){ //开始时间是否是节假日
                            if($get_whitelist){ //开始时间是否是白名单
                                if($original_end== 1 || $original_end == 2 || $original_end == 3 || $original_end == 4 || $original_end == 5){  //结束时间工作日 开始时间是白名单
                                    if($get_festival_e){ //判断结束时间是不是假节日
                                        if($get_whitelist_e){  //判断结束时间是否是白名单 那么工作日天数是1
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{ //如果结束时间不是白名单 说明结束时间 是节假日 那么 周末天数和节假日天数都是0.5天
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日 那么 开始时间和结束时间都是工作日
                                        $work = 1;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }
                                }
                                else //结束时间是周末 开始时间是白名单
                                {
                                    if ($get_festival_e) {//结束时间是节假日
                                        if ($get_whitelist_e) {//结束时间是否是白名单
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{//结束时间不是白名单 开始时间是白名单
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日
                                        if ($get_whitelist_e) {//结束时间是否是白名单
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{
                                            $work = 0.5;
                                            $weeks = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                        }

                                    }
                                }
                            }
                            else{ // 开始时间 不是白名单 是假节日
                                if($original_end== 1 || $original_end == 2 || $original_end == 3 || $original_end == 4 || $original_end == 5){  //如果是 判断结束时间是周几
                                    if($get_festival_e){ //判断结束时间是不是假节日
                                        if($get_whitelist_e){  //判断结束时间是否是白名单
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{ //如果不是白名单
                                            $festival = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日
                                        $work = 0.5;
                                        $festival = 0.5;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }
                                }
                                else //结束时间是周末  开始时间是假节日
                                {
                                    if ($get_festival_e) {//结束时间是否是节假日
                                        if ($get_whitelist_e) {//结束时间是否是白名单
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{
                                            $festival = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{//结束时间不是节假日 是周末
                                        if ($get_whitelist_e) { //结束时间是否是白名单
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{//结束时间不是白名单 是周末
                                            $weeks = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                        }

                                    }
                                }
                            }
                        }
                        else{ //开始时间 是周末
                            if($get_whitelist){ //是白名单
                                if($original_end== 1 || $original_end == 2 || $original_end == 3 || $original_end == 4 || $original_end == 5){  //结束时间工作日 开始时间是白名单
                                    if($get_festival_e){ //判断结束时间是不是假节日
                                        if($get_whitelist_e){  //判断结束时间是否是白名单 那么工作日天数是1
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{ //如果结束时间不是白名单 说明结束时间 是节假日 那么 工作日天数(开始时间是白名单)和节假日天数都是0.5天
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日 是工作日 开始时间是白名单
                                        $work = 1;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }
                                }
                                else //结束时间是周末 开始时间是白名单
                                {
                                    if ($get_festival_e) {//结束时间是节假日
                                        if ($get_whitelist_e) {//结束时间是否是白名单
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{//结束时间不是白名单 是节假日 开始时间是白名单
                                            $work = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日是周末  开始时间是白名单
                                        if ($get_whitelist_e) {//结束时间是否是白名单 开始时间是白名单
                                            $work = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{//结束时间不是白名单 是周末 开始时间是白名单
                                            $weeks = 0.5;
                                            $work = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                        }

                                    }
                                }
                            }
                            else //开始时间不是白名单 是周末
                            {
                                if($original_end== 1 || $original_end == 2 || $original_end == 3 || $original_end == 4 || $original_end == 5){  //结束时间工作日 开始时间是白名单
                                    if($get_festival_e){ //判断结束时间是不是假节日
                                        if($get_whitelist_e){  //判断是否是白名单 那么工作日天数和周末各半天
                                            $weeks = 0.5;
                                            $work = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{ //如果不是白名单 说明结束时间 是节假日 那么 周末天数和节假日天数都是0.5天
                                            $weeks = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日  开始时间是周末
                                        $work = 0.5;
                                        $weeks = 0.5;
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                        $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                    }
                                }
                                else //结束时间是周末 开始时间是周末
                                {
                                    if ($get_festival_e) {//结束时间是节假日
                                        if ($get_whitelist_e) {//结束时间是否是白名单
                                            $work = 0.5;
                                            $weeks = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{ //结束时间是节假日  开始时间是周末
                                            $weeks = 0.5;
                                            $festival = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>0.5);
                                        }
                                    }else{ //结束时间不是节假日是周末 开始时间是周末
                                        if ($get_whitelist_e) {//结束时间是否是白名单
                                            $work = 0.5;
                                            $weeks = 0.5;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0.5);
                                        }else{
                                            $weeks = 1;
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                            $date_price_array[] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>0.5);
                                        }

                                    }
                                }
                            }

                        }
                    }
//var_dump($date_price_array);exit;
                    //判断开始时间和结束时间是否大于六小时 并且是不是在营业开始时间还车
                    //判断开始车时
                    if($original_end == '1' || $original_end == '2' || $original_end == '3' || $original_end == '4' || $original_end == '5'){
                        $hour = (strtotime($endtime) - strtotime($store_end1)) / 3600;
                        $hour_s = (strtotime($store_start2) - strtotime($starttime)) / 3600;
                        if ($hour == 0 && $hour_s<=6) {
                            if ($get_festival_e) {
                                if ($get_whitelist_e) {
                                    $work = $work - 0.5;
                                    $date_price_array[0]['day'] = 0.5;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                } else {
                                    $festival = $festival - 0.5;
                                    $date_price_array[0]['day'] = 0.5;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                }
                            } else {
                                $work = $work - 0.5;
                                $date_price_array[0]['day'] = 0.5;
                                $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                            }
                        }
                        if($hour == 0 && $hour_s>6){
                            if ($get_festival_e) {
                                if ($get_whitelist_e) {
                                    $date_price_array[0]['day'] = 1;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                } else {
                                    $date_price_array[0]['day'] = 1;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                }
                            } else {
                                $date_price_array[0]['day'] = 1;
                                $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                            }
                        }
                    }
                    if ($original_end == '0' || $original_end == '6') {
                        $hours = (strtotime($endtime) - strtotime($store_end1)) / 3600;
                        $hour_s = (strtotime($store_start2) - strtotime($starttime)) / 3600;
                        if($hours==0 && $hour_s<=6){
                            if ($get_festival_e) {
                                if ($get_whitelist_e) {
                                    $work = $work - 0.5;
                                    $date_price_array[0]['day'] = 0.5;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                } else {
                                    $festival = $festival - 0.5;
                                    $date_price_array[0]['day'] = 0.5;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                }
                            } else {
                                if ($get_whitelist_e) {
                                    $work = $work - 0.5;
                                    $date_price_array[0]['day'] = 0.5;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                } else {
                                    $weeks = $weeks - 0.5;
                                    $date_price_array[0]['day'] = 0.5;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                }
                            }
                        }
                        if($hours==0 && $hour_s>6){
                            if ($get_festival_e) {
                                if ($get_whitelist_e) {
                                    $date_price_array[0]['day'] = 1;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                } else {
                                    $date_price_array[0]['day'] = 1;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                }
                            } else {
                                if ($get_whitelist_e) {
                                    $date_price_array[0]['day'] = 1;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                } else {
                                    $date_price_array[0]['day'] = 1;
                                    $date_price_array[1] = array('date'=>date("Y-m-d",strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>0);
                                }
                            }
                        }
                    }
                }
            }

            //租期超过24小时
            else
            {
                //先把车时开始/结束时间 变成整数 为了计算整天数
                $upd_starts = date('Y-m-d', strtotime($starttime)) . ' 23:59:59';
                $upd_ends = date('Y-m-d', strtotime($endtime)) . ' 23:59:59';
                for ($i = strtotime($upd_starts); $i <= strtotime($upd_ends); $i += 86400) {
                    $t = date("Y-m-d", $i);
                    $get_number = date("w", strtotime($t));//获取星期数
                    $get_festival = $this->getFestivals($t);//判断是否是节假日
                    $get_whitelist = $this->getWhiteList($t);//判断是否在白名单内 如果在就按照工作日算
                    //var_dump($get_whitelist);
                    //判断是否是工作日
                    if ($get_number == 1 || $get_number == 2 || $get_number == 3 || $get_number == 4 || $get_number == 5) {
                        if ($get_festival) {
                            if ($get_whitelist) {
                                $work++;
                                $date_price_array[] = array('date'=>date("Y-m-d", $i),'rent'=>$result[0][0]['@rentprice'],'day'=>1);
                            } else {
                                $festival++;
                                $date_price_array[] = array('date'=>date("Y-m-d", $i),'rent'=>$result[0][0]['@festivalsprice'],'day'=>1);
                            }
                        } else {
                            $work++;
                            $date_price_array[] = array('date'=>date("Y-m-d", $i),'rent'=>$result[0][0]['@rentprice'],'day'=>1);
                        }
                    }
                    //判断是否是周末
                    if ($get_number == 0 || $get_number == 6) {
                        if ($get_festival) {
                            if ($get_whitelist) {
                                $work++;
                                $date_price_array[] = array('date'=>date("Y-m-d", $i),'rent'=>$result[0][0]['@rentprice'],'day'=>1);
                            } else {
                                $festival++;
                                $date_price_array[] = array('date'=>date("Y-m-d", $i),'rent'=>$result[0][0]['@festivalsprice'],'day'=>1);
                            }
                        } else {
                            if ($get_whitelist) {
                                $work++;
                                $date_price_array[] = array('date'=>date("Y-m-d", $i),'rent'=>$result[0][0]['@rentprice'],'day'=>1);
                            } else {
                                $weeks++;
                                $date_price_array[] = array('date'=>date("Y-m-d", $i),'rent'=>$result[0][0]['@weekprice'],'day'=>1);
                            }
                        }
                    }
                }
                //判断原车时 开始时间
                $original_start = date("w", strtotime($starttime));
                //如果原开始时间是周一到周五
                if ($original_start == '1' || $original_start == '2' || $original_start == '3' || $original_start == '4' || $original_start == '5') {
                    $t = date("Y-m-d", strtotime($starttime));
                    $get_festival = $this->getFestivals($t);//判断是否是节假日
                    $get_whitelist = $this->getWhiteList($t);//判断是否在白名单内 如果在就按照工作日算
                    $hour = (strtotime($store_start2) - strtotime($starttime)) / 3600;
                    if ($hour < 6) {
                        if ($get_festival) {
                            if ($get_whitelist) {
                                $work = $work - 0.5;
                                $date_price_array[0] = array('date'=>date("Y-m-d", strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[0]['day']-0.5);

                            } else {
                                $festival = $festival - 0.5;
                                $date_price_array[0] = array('date'=>date("Y-m-d", strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>$date_price_array[0]['day']-0.5);
                            }
                        } else {
                            $work = $work - 0.5;
                            $date_price_array[0] = array('date'=>date("Y-m-d", strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[0]['day']-0.5);

                        }
                    }
                }
                //如果原开始时间是周六 周天
                if ($original_start == '0' || $original_start == '6') {
                    $t = date("Y-m-d", strtotime($starttime));
                    $get_festival = $this->getFestivals($t);//判断是否是节假日
                    $get_whitelist = $this->getWhiteList($t);//判断是否在白名单内 如果在就按照工作日算
                    $hours = (strtotime($store_start2) - strtotime($starttime)) / 3600;
                    if ($hours < 6) {
                        if ($get_festival) {
                            if ($get_whitelist) {
                                $work = $work - 0.5;
                                $date_price_array[0] = array('date'=>date("Y-m-d", strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[0]['day']-0.5);
                            } else {
                                $festival = $festival - 0.5;
                                $date_price_array[0] = array('date'=>date("Y-m-d", strtotime($starttime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>$date_price_array[0]['day']-0.5);
                            }
                        } else {
                            if ($get_whitelist) {
                                $work = $work - 0.5;
                                $date_price_array[0] = array('date'=>date("Y-m-d", strtotime($starttime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[0]['day']-0.5);
                            } else {
                                $weeks = $weeks - 0.5;
                                $date_price_array[0] = array('date'=>date("Y-m-d", strtotime($starttime)),'rent'=>$result[0][0]['@weekprice'],'day'=>$date_price_array[0]['day']-0.5);
                            }
                        }
                    }
                }

                //var_dump($date_price_array);exit;
                //判断原车时 结束时间
                $original_end = date("w", strtotime($endtime));
                //如果原结束时间是周一到周五
                if ($original_end == '1' || $original_end == '2' || $original_end == '3' || $original_end == '4' || $original_end == '5') {
                    $t = date("Y-m-d", strtotime($endtime));
                    $get_festival = $this->getFestivals($t);//判断是否是节假日
                    $get_whitelist = $this->getWhiteList($t);//判断是否在白名单内 如果在就按照工作日算
                    $hour = (strtotime($endtime) - strtotime($store_end1)) / 3600;
                    if ($hour < 6 && $hour >0) {
                        if ($get_festival) {
                            if ($get_whitelist) {
                                $work = $work - 0.5;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-0.5);
                            } else {
                                $festival = $festival - 0.5;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-0.5);
                            }
                        } else {
                            $work = $work - 0.5;
                            $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-0.5);
                        }
                    }
                    if($hour==0){
                        if ($get_festival) {
                            if ($get_whitelist) {
                                $work = $work - 1;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-1);
                            } else {
                                $festival = $festival - 1;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-1);
                            }
                        } else {
                            $work = $work - 1;
                            $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-1);
                        }
                    }
                }
                //var_dump($original_end);exit;
                //如果原结束时间是周六 周日
                if ($original_end == '0' || $original_end == '6') {
                    $t = date("Y-m-d", strtotime($endtime));
                    $get_festival = $this->getFestivals($t);//判断是否是节假日
                    $get_whitelist = $this->getWhiteList($t);//判断是否在白名单内 如果在就按照工作日算
                    $hours = (strtotime($endtime) - strtotime($store_end1)) / 3600;

                    if ($hours < 6 && $hours >0) {
                        //var_dump($date_price_array);exit;
                        if ($get_festival) {
                            if ($get_whitelist) {
                                $work = $work - 0.5;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-0.5);
                            } else {
                                $festival = $festival - 0.5;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-0.5);
                            }
                        } else {
                            if ($get_whitelist) {
                                $work = $work - 0.5;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-0.5);
                            } else {
                                $weeks = $weeks - 0.5;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-0.5);
                            }
                        }
                    }
                    if($hours==0){
                        if ($get_festival) {
                            if ($get_whitelist) {
                                $work = $work - 1;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-1);
                            } else {
                                $festival = $festival - 1;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@festivalsprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-1);
                            }
                        } else {
                            if ($get_whitelist) {
                                $work = $work - 1;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@rentprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-1);
                            } else {
                                $weeks = $weeks - 1;
                                $date_price_array[count($date_price_array)-1] = array('date'=>date("Y-m-d", strtotime($endtime)),'rent'=>$result[0][0]['@weekprice'],'day'=>$date_price_array[count($date_price_array)-1]['day']-1);
                            }
                        }
                    }
                }
            }

            //var_dump($date_price_array);exit;
            $array['workprice'] = $result[0][0]['@rentprice'];//日租金
            $array['weekprice'] = $result[0][0]['@weekprice'];//周末租金
            $array['festivalprice'] = $result[0][0]['@festivalsprice'];//假期租金
            $array['addprice'] = $result[0][0]['@limitprice'];//限牌价
            $array['daycounts'] = $work + $weeks + $festival; //车时总天数
            $array['work'] = $work;//工作日天数
            $array['weeks'] = $weeks;//周末天数
            $array['festival'] = $festival;//节假日天数
            $array['standard_total_prices'] = $result[0][0]['@rentprice']*$work+$result[0][0]['@weekprice']*$weeks+$result[0][0]['@festivalsprice']*$festival+$result[0][0]['@limitprice']*$array['daycounts'];//基准总租金
            $array['car_price'] = $result[0][0]['@buying_price'];//汽车指导价
            $array['coefficien'] = $result[0][0]['@coefficient'];//系数
            $array['yearcoefficient'] = $result[0][0]['@yearcoefficient'];//年限系数
            $array['work_multiple'] = $result[0][0]['@work_multiple'];//工作日租金倍数
            $array['week_multiple'] = $result[0][0]['@week_multiple'];//周末租金倍数
            $array['festivals_multiple'] = $result[0][0]['@festivals_multiple'];//假节日租金倍数
            $array['car_cash'] = $result[0][0]['@car_cash'];//车辆押金
            $array['date_list']=$date_price_array;  //日期列表 价格 天数

            //门店调价日期 计算
            $storearray['Procedure_data_in'] = array('_store_id'=>$store_id);
            $storearray['Procedure_name'] = 'CalculateStoreDateConfig';
            $storeresult = $Procedure->CallProcedure_query($storearray);

            if (array_key_exists('result', $storeresult)) {
                $array['sum_store_date']=0;
                $array['store_date_config']= array();
            }else {
                $store_date_config = array();
                //判断数组是否为空
                $sum_store_date = '';
                if(count($storeresult[0])>0){
                    foreach($storeresult[0] as $key =>$value){
                        foreach($date_price_array as $k => $v){
                            if($v['date']>=$value['time_start'] && $v['date']<=$value['time_end']){
                                $store_week = date("w", strtotime($v['date'])); //在门店配置里的日期是周几
                                $store_festival = $this->getFestivals($v['date']);//判断是否是节假日
                                $store_whitelist = $this->getWhiteList($v['date']);//判断是否在白名单内 如果在就按照工作日算
                                if($store_week == 1 || $store_week == 2 || $store_week == 3 || $store_week == 4 || $store_week == 5){//在门店配置里的日期是工作日
                                    if($store_whitelist){ //是不是白名单
                                        $store_date_price = $result[0][0]['@rentprice']*($value['coefficient']-1)*$v['day'];
                                        $price = $result[0][0]['@rentprice'];
                                    }else{//不是白名单
                                        if($store_festival){ //是不是节假日
                                            $store_date_price = $result[0][0]['@festivalsprice']*($value['coefficient']-1)*$v['day'];
                                            $price = $result[0][0]['@festivalsprice'];
                                        }else{
                                            $store_date_price = $result[0][0]['@rentprice']*($value['coefficient']-1)*$v['day'];
                                            $price = $result[0][0]['@rentprice'];
                                        }
                                    }
                                }
                                //在门店配置里的日期是周六或周日
                                else{
                                    if($store_whitelist){ //是不是白名单
                                        $store_date_price = $result[0][0]['@rentprice']*($value['coefficient']-1)*$v['day'];
                                        $price = $result[0][0]['@rentprice'];
                                    }else{ //不是白名单
                                        if($store_festival){ //是不是节假日
                                            $store_date_price = $result[0][0]['@festivalsprice']*($value['coefficient']-1)*$v['day'];
                                            $price = $result[0][0]['@festivalsprice'];
                                        }else{
                                            $store_date_price = $result[0][0]['@weekprice']*($value['coefficient']-1)*$v['day'];
                                            $price = $result[0][0]['@weekprice'];
                                        }
                                    }
                                }
                                $store_date_config[] = array('store_date'=>$v['date'],'store_date_price'=>$store_date_price,'price'=>$price,'coefficient'=>$value['coefficient'],'day'=>$v['day']);
                                $sum_store_date += $store_date_price;
                            }
                        }
                    }
                }else{
                    $array['store_date_config']= array();
                }
                $array['sum_store_date']= $sum_store_date;//门店日期配置差价 总价
                $array['store_date_config']= $store_date_config; //门店调价日期配置 日期 差价

            }


            // var_dump($array);exit;

            return array('successed' => true, 'msg' => $array);
        }



    }


    //节假日筛选
    private function getFestivals($data)
    {
        $array = Yii::$app->params['FestivalsConfig'];
        foreach ($array as $key=>$val) {
            if(in_array($data,$array[$key])){
                return true;
            }else{
                return false;
            }
        }
    }

    //白名单中筛选
    private function getWhiteList($data)
    {
        $array = Yii::$app->params['WhiteList'];

        if(in_array($data,$array)){
            return true;
        }else{
            return false;
        }
    }

}




